package adminorg;

import java.io.Serializable;

import com.vaadin.ui.Button;
import com.vaadin.ui.Form;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;


public class formWindow extends Window implements Button.ClickListener{
	/**
	 * 
	 */
	private static final long serialVersionUID = -5992877008551887021L;
	Callback callback;
	Button close = new Button("Отмена",this);
	Button submit = new Button("ОК",this);
	Form F = new Form();
	
	public formWindow(String caption, Form F, Callback callback){
		super(caption);
		setModal(true);
		VerticalLayout layout = (VerticalLayout) this.getContent();
		layout.setSizeUndefined();
		this.callback = callback;
		this.F=F;
    	HorizontalLayout h = new HorizontalLayout();
      	h.addComponent(submit);
    	h.addComponent(close);
    	this.F.setFooter(h);
    	layout.addComponent(this.F);
	}

	@Override
	public void buttonClick(ClickEvent event) {
		if (event.getSource() == submit){
			this.F.commit();
			if (!this.F.isValid()) {
	            return;
	        }
		}		 
		if (getParent() != null) {
            ((Window) getParent()).removeWindow(this);
        }
        callback.onDialogResult(event.getSource() == submit);
		
	}
	
	 public interface Callback extends Serializable {

	        public void onDialogResult(boolean resultIsYes);
	    }

}
